package com.sh.data.engine.domain.integration.online.model.domain;

import com.sh.data.engine.common.util.FlinkSqlUtil;
import lombok.Builder;
import lombok.Data;
import lombok.experimental.Tolerate;

import java.util.List;

@Data
@Builder(toBuilder = true)
public class TableConfigDomain {

    private Long dsId;
    private String dsType;
    private String tableName;
    /**
     * 用来临时生成hive表时候使用
     */
    private Boolean supportText = Boolean.TRUE;
    /**
     * 0-默认 1-latest-offset
     */
    private Integer start;

    private List<FieldInfo> fieldInfoList;

    private String schema;

    /**
     * 借鉴 OfflineTaskCreateTableMappingResponse.Field
     */
    @Data
    @Builder(toBuilder = true)
    public static class FieldInfo {
        private String name;
        private String type;
        private Boolean isPartition = Boolean.FALSE;
        private Boolean isPk = Boolean.FALSE;

        /**
         * 应对flink sql中的种类的不支持<br>
         * 转换成flink sql支持的<br>
         * 转换成flinksql中的种类后两边需要一样
         */
        public String getChangeType() {
            return FlinkSqlUtil.dbColumnType2FlinkSqlColumnType(type);
        }

        public String getType() {
            return type;
        }

        @Tolerate
        public FieldInfo() {
        }
    }

    private Boolean isSource = Boolean.FALSE;

    // 默认都是使用cdc模式
    private Boolean useCdc = Boolean.TRUE;

    @Tolerate
    public TableConfigDomain() {
    }
}
